package com.glb;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * App class test
 * <strong> First java class </strong>
 */
public class App extends ArrayList<Integer> {

    public static void main(String[] args) {
        Integer n1 = Integer.valueOf(120);
        Integer n2 = Integer.valueOf(120);
        System.out.println(n1 == n2); // true
    }

    public static void printWords(String s) {

        // Splits Str into all possible tokens
        for (String word : s.split(" "))

            // if length is even
            // if (word.length() % 2 == 0)

                // Print the word
                System.out.println(word);
    }

    // Driver Code15
    public static void main15(String[] args) {

        String s = "i am Geeks for Geeks and a Geek";
        printWords(s);
    }

    // Main driver method
    public static void main14(String[] args) {
        // Create destination list
        List<String> destination_List = new ArrayList<>();

        // Add elements
        destination_List.add("Shoes");
        destination_List.add("Toys");
        destination_List.add("Horse");
        // destination_List.add("Tiger");

        // Print the elements
        System.out.println(
                "The Original Destination list is ");

        for (int i = 0; i < destination_List.size(); i++) {
            System.out.print(destination_List.get(i) + " ");
        }
        System.out.println();

        // Create source list
        List<String> source_List = new ArrayList<>();

        // Add elements
        source_List.add("Bat");
        source_List.add("Frog");
        source_List.add("Lion");

        // Copy the elements from source to destination
        Collections.copy(destination_List, source_List);

        // Printing the modified list
        System.out.println(
                "The Destination List After copying is ");

        for (int i = 0; i < destination_List.size(); i++) {
            System.out.print(destination_List.get(i) + " ");
        }
    }

    // Main driver method
    public static void main13(String[] args) {
        // Creating a list
        // Declaring object of string type
        List<String> items = new ArrayList<>();

        // Adding elements to the list
        // using add() method
        items.add("Shoes");
        items.add("Toys");

        // Adding one or more elements using addAll()
        Collections.addAll(items, "Fruits", "Bat", "Mouse");

        // Sorting according to default ordering
        // using sort() method
        Collections.sort(items);

        // Printing the elements
        for (int i = 0; i < items.size(); i++) {
            System.out.print(items.get(i) + " ");
        }

        System.out.println();

        // Sorting according to reverse ordering
        Collections.sort(items, Collections.reverseOrder());

        // Printing the reverse order
        for (int i = 0; i < items.size(); i++) {
            System.out.print(items.get(i) + " ");
        }
    }

    // Main Method
    public static void main12(String args[]) {
        // Creating empty priority queue
        PriorityQueue<Integer> pQueue = new PriorityQueue<Integer>();

        // Adding items to the pQueue using add()
        pQueue.add(10);
        pQueue.add(20);
        pQueue.add(15);

        // Printing the top element of PriorityQueue
        System.out.println(pQueue.peek());

        // Printing the top element and removing it
        // from the PriorityQueue container
        System.out.println(pQueue.poll());

        // Printing the top element again
        System.out.println(pQueue.poll());
        System.out.println(pQueue.poll());
        System.out.println(pQueue.peek());
        System.out.println(pQueue.peek());
    }

    public static void main11(String[] args) {
        File Obj = new File("myfile.txt");
        if (Obj.delete()) {
            System.out.println("The deleted file is : "
                    + Obj.getName());
        } else {
            System.out.println(
                    "Failed in deleting the file.");
        }
    }

    public static void main10(String[] args) {
        try {
            FileWriter Writer = new FileWriter("myfile.txt");
            Writer.write(
                    "Files in Java are seriously good!!");
            Writer.close();
            System.out.println("Successfully written.");
        } catch (IOException e) {
            System.out.println("An error has occurred.");
            e.printStackTrace();
        }
    }

    public static void main9(String[] args) {
        try {
            File Obj = new File("myfile.txt");
            Scanner Reader = new Scanner(Obj);
            while (Reader.hasNextLine()) {
                String data = Reader.nextLine();
                System.out.println(data);
            }
            Reader.close();
        } catch (FileNotFoundException e) {
            System.out.println("An error has occurred.");
            e.printStackTrace();
        }
    }

    public static void main8(String[] args) {
        try {
            File Obj = new File("myfile.txt");
            if (Obj.createNewFile()) {
                System.out.println("File created: "
                        + Obj.getName());
            } else {
                System.out.println("File already exists.");
            }
        } catch (IOException e) {
            System.out.println("An error has occurred.");
            e.printStackTrace();
        }
    }

    public static void main7(String[] args) {
        List<Integer> al = new ArrayList<Integer>();
        al.add(10);
        al.add(20);
        al.add(30);
        al.add(40);

        Integer[] arr = new Integer[al.size() + 1];
        Integer[] arr2 = al.toArray(arr);
        arr2[0] = 11111;

        for (Integer x : arr)
            System.out.print(x + " ");
    }

    public static void main6(String[] args) {
        // Creating an empty array list
        HashSet<String> bags = new HashSet<String>();

        // Add values in the bags Set.
        // bags.add("pen");
        // bags.add("ink2");
        // bags.add("paper");
        // bags.add("pen");
        bags.add("paper");
        bags.add("books");
        bags.add("rubber");
        bags.add("ink");
        bags.add("ink2");
        bags.add("ink3");

        // Creating another empty array list
        ArrayList<String> boxes = new ArrayList<String>();

        // Add values in the boxes list.
        boxes.add("pen");
        boxes.add("paper");
        boxes.add("books");
        boxes.add("rubber");
        boxes.add("ink");

        // Before Applying method print both list and set.
        System.out.println("Bags Contains :" + bags);
        System.out.println("Boxes Contains :" + boxes);

        // Apply retainAll() method to boxes passing bags as parameter
        boolean retainResult = boxes.retainAll(bags);
        System.out.println(retainResult);

        // Displaying both the lists after operation
        System.out.println("\nAfter Applying retainAll()" +
                " method to Boxes\n");
        System.out.println("Bags Contains :" + bags);
        System.out.println("Boxes Contains :" + boxes);
    }

    public static void main5(String[] args) {

        // create an empty array list

        App arr = new App();

        // use add() method to add values in the list
        arr.add(1);
        arr.add(2);
        arr.add(3);
        arr.add(12);
        arr.add(9);
        arr.add(13);

        // prints the list before removing
        System.out.println("The list before using removeRange:" + arr);

        // removing range of 1st 2 elements
        arr.removeRange(0, 2);
        System.out.println("The list after using removeRange:" + arr);
    }

    public static void main4(String[] args) {

        // create an ArrayList which going to
        // contains a list of Numbers
        ArrayList<Integer> Numbers = new ArrayList<Integer>();

        // Add Number to list
        Numbers.add(23);
        Numbers.add(32);
        Numbers.add(45);
        Numbers.add(63);

        // apply removeIf() method
        // we are going to remove numbers divisible by 3
        boolean removeResult = Numbers.removeIf(n -> (n % 5 == 0));
        System.out.println(removeResult);

        // print list
        for (int i : Numbers) {
            System.out.println(i);
        }
    }

    // Main driver method
    public static void main3(String[] args) {
        // Creating an Empty Integer ArrayList
        ArrayList<Integer> arr = new ArrayList<Integer>(4);

        // Using add() method to insert elements
        // and adding custom values
        arr.add(10);
        arr.add(20);
        arr.add(30);
        arr.add(40);
        System.out.println(arr);

        // Getting element at index 2
        // int element = arr.get(4);
        int element = arr.get(2);

        // Print all the elements of ArrayList
        System.out.println("the element at index 2 is "
                + element);
    }

    int abc;

    public App() {
        System.out.println(abc);
        test();
        System.out.println("============");
    }

    private void test() {
        System.out.println(abc);

    }

    // Main driver method
    public static void main2(String args[]) {
        // Creating an Array of string type
        ArrayList<String> al = new ArrayList<>(10);

        // Adding elements to ArrayList
        // Custom inputs
        al.add("Geeks");
        al.add("Geeks");

        // Here we are mentioning the index
        // at which it is to be added
        al.add(1, "For");
        al.add(3, "For222");

        // Printing all the elements in an ArrayList
        System.out.println(al);
    }

    public static void main1(String... args) throws Exception {

        // Get the Array
        int intArr[] = { 10, 20, 15, 22, 35 };

        // To convert the elements as List
        System.out.println("Integer Array as List: "
                + Arrays.asList(intArr).spliterator());

        // String windowsString = "Hello\r\nWorld";
        // String unixString = "Hello\nWorld";
        // System.out.println(windowsString);
        // System.out.println(unixString);

        // // Unix/Linux newline
        // String unixNewline = "\n";
        // // Windows newline
        // String windowsNewline = "\r\n";
        // System.out.println(unixNewline.getBytes().length);
        // System.out.println(windowsNewline.getBytes().length);
        // // String with Unix newlines
        // String textWithUnixNewlines = "First line." + unixNewline + "Second line." +
        // unixNewline + "Third line.";
        // // String with Windows newlines
        // String textWithWindowsNewlines = "First line." + windowsNewline + "Second
        // line." + windowsNewline + "Third line.";

        // // Print the strings with Unix newlines
        // System.out.println("Text with Unix newlines:");
        // System.out.println(textWithUnixNewlines);

        // // Print the strings with Windows newlines
        // System.out.println("Text with Windows newlines:");
        // System.out.println(textWithWindowsNewlines);
        return;
        // System.out.println(System.getProperty("os.name"));

        // System.out.print( (int)Math.round(360 * 1.0 / 365 * 100));

        // System.out.println(1 << 2);
        // System.out.println("============");

        // // TODO, 这里不懂： e.next = (Entry<K,V>)newMap[index];
        // var hash = new Hashtable<String, Integer>();
        // var result1 = hash.put("test1", 123);
        // var result2 = hash.put("test2", 124);
        // var result3 = hash.put("test1", 125);
        // System.out.println(result1);
        // System.out.println(result2);
        // System.out.println(result3);
        // hash.put("test2", 1234);
        // System.out.println(hash.toString());
        // System.out.println("============");

        // var list = new ArrayList<String>();
        // list.add("list1");
        // list.add("list2");
        // list.add("list3");
        // list.add("list4");
        // list.size();
        // System.out.println(list);

        // System.out.println("============");

        // float d1 = 4.0f;
        // float d2 = 3.6f;
        // System.out.println(d1 - d2);

        // System.out.println("============");
        // Integer a = 100;
        // Integer b = 100;
        // System.out.println(a == b);

        // System.out.println("============");
        // for (int i = 1; i < 10; i++) {
        // if (i > 5) {
        // return;
        // }
        // System.out.println(i);
        // }

        // System.out.println("============");

        // App app = new App();

        // System.out.println("Hello, World!");
        // int age = 13;
        // String rating = "PG" + (age + 1);

        // System.out.println(rating);
        // System.out.println(String.join("/", "a", "b", "c"));

        // // char* greeting = "Hello";
        // String str = "Hello, 世界!";

        // System.out.println("============");
        // for (int i = 0; i < str.length(); i++) {
        // System.out.println(str.charAt(i));
        // }

        // System.out.println("============");

        // IntStream codePoints = str.codePoints();
        // codePoints.forEach(codePoint -> {
        // // Perform operations on each code point
        // System.out.println("Code point: " + codePoint);
        // });
        // System.out.println("============");

        // System.out.println(str.isBlank());

        // System.out.printf("%s %s %tB %<te, %<tY %s", "Due Date:", "(test)", new
        // Date(), "(end)");

        // System.out.println("");
        // System.out.println("============");

        // System.out.println(new Date());
        // System.out.println(LocalDate.now().getMonthValue());
        // System.out.println("============");

    }
}
